/*D6qijQE+tseVhRgdMUhc8CLVdMmv09xZj2cRjKys5OjpqUeR2C2n15oVAspWaZLV*/
/*
 * @Author: xiahui 
 * @PageInfo: 卡片删除 
 * @Date: 2019-01-17 09:37:38 
 * @Last Modified by: zhr
 * @Last Modified time: 2021-10-22 14:22:28
 */
import { ajax } from 'nc-lightapp-front';
import { URL, AREA, DATASOURCECACHE, FIELDS, CACHESTATUS, PAGECODE } from '../../constance';
import { getNextId } from '../../../../../scmpub/scmpub/pub/cache';
import pageInfoClick from './pageInfoClick';
import { showSuccessInfo, showSingleDeleteDialog } from '../../../../../scmpub/scmpub/pub/tool/messageUtil';
import { setCardCacheData } from '../../utils/cardPageUtil';
import { getLangByResId } from '../../../../../scmpub/scmpub/pub/tool/multiLangUtil';

export default function deleteBtnClick(props) {
	showSingleDeleteDialog({
		beSureBtnClick: () => {
			let reqData = {
				infos: [
					{
						id: props.form.getFormItemsValue(AREA.cardFormId, FIELDS.pk_ct_pu).value,
						ts: props.form.getFormItemsValue(AREA.cardFormId, FIELDS.ts).value
					}
				]
			};

			ajax({
				url: URL.delete,
				data: reqData,
				success: (res) => {	
					if (res.success && res.data) {
						debugger;
						let source = this.props.getUrlParam('source');
						// 根据当前id,获取下个id
						let cbillid = res.data.successIds[0];
						let nextId = getNextId(props, cbillid, DATASOURCECACHE.dataSourceListCacheKey);
						// 删除当前页缓存数据
						setCardCacheData.call(this, props, res.data, CACHESTATUS.delete);
						//分摊明细保存后重新查询 xugao 2022-10-31 09:48:00
						this.props.cardTable.setTableData('list_head', { rows: [] });
						if (source == URL.ref20 || source == URL.ref28) {
							let pagecode = source == URL.ref20 ? PAGECODE.ref20Pagecode : PAGECODE.ref28Pagecode;
							if (props.transferTable.getTransformFormAmount(AREA.cardLeftId) == 1) {
								// 转单-剩一条时，返回上级页面
								window.onbeforeunload = null;
								props.pushTo(source, { pagecode: pagecode });
							} else {
								props.transferTable.setTransformFormStatus(AREA.cardLeftId, {
									status: false,
									onChange: (current, next) => {
										showSuccessInfo(getLangByResId(this, '4004PURDAILY-000010')); /* 国际化处理： 删除成功*/
									}
								});
							}
						} else {
							showSuccessInfo(getLangByResId(this, '4004PURDAILY-000010')); /* 国际化处理： 删除成功*/
							// 查询下一页数据
							pageInfoClick.call(this, props, nextId);
						//分摊明细保存后重新查询 xugao 2022-10-31 09:48:00
						// let billid = this.props.getUrlParam('id');
						// let billid = props.form.getFormItemsValue(AREA.cardFormId, FIELDS.pk_ct_pu).value;
        				let billid =nextId;
						if(billid){
            			ajax({
                		url:'/nccloud/ct/purdaily/queryShare.do',
                		data:{
                    		pk_ct_pu:billid,
                    		pagecode: PAGECODE.cardPagecode,
                    		appcode: this.state.appcode
                		},
                		success: (res) => {
                    	console.log(res,"resssss")
                    	if (res.success && res.data) {
                        if(res.data['body'].rows.length>0){
                            //处理分摊明细数据
                            this.props.cardTable.setTableData('list_head', res.data['body']);
                        }else{
                            //  清空分摊明细数据
                            this.props.cardTable.setTableData('list_head',{rows:[]});
                        }
                        
                    	}
                	}
            	});
        	}							
						}
					}
				}
			});
		}
	});
}

/*D6qijQE+tseVhRgdMUhc8CLVdMmv09xZj2cRjKys5OjpqUeR2C2n15oVAspWaZLV*/
